/**
 * Copyright (C) 2009 Fsti Inc.
 *
 */
package com.fsti.ppmw.action;

import java.util.concurrent.ExecutionException;

import org.apache.struts2.ServletActionContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.fsti.ppmw.port.payment.Client;
import com.fsti.ppmw.port.payment.PaymentDAO;
import com.fsti.ppmw.port.payment.RequestParams;


/**
 * @author Song Qing
 *
 */
public class Payment{

	private Client client;
	
	private String message;
	
	public static String RETURN_VALUE_SPLIT_STR="^";
	
	public String execute() throws InterruptedException, ExecutionException {
		RequestParams params=new RequestParams();
		params.setRequestId(getParameter("RequestID"));
		params.setAbilityType(getParameter("abilityType"));
		params.setAreaCode(getParameter("areaCode"));
		params.setPassword(getParameter("password"));
		params.setPayorgId(getParameter("payorgId"));
		params.setTimeStamp(getParameter("timeStamp"));
		params.setUserTel(getParameter("userTel"));
		params.setApUser(params.getUserTel());
		
		WebApplicationContext context=WebApplicationContextUtils.getWebApplicationContext(ServletActionContext.getServletContext());
		PaymentDAO paymentDAO=(PaymentDAO)context.getBean("paymentDAO");
	
		String returnValue=client.call(params,paymentDAO);
		
		//生成返回字符串
		message=returnValue;
		
		return "SUCCESS";
	}

	/**
	 * 获取参数值
	 * @param str
	 */
	private String getParameter(String str) {
		return ServletActionContext.getRequest().getParameter(str);
	}

	public void setClient(Client client) {
		this.client = client;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

}
